package com.ruoyi.web.controller.car;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarSpec;
import com.ruoyi.car.service.ICarSpecService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆规格Controller
 * 
 * @author zls
 * @date 2020-03-29
 */
@Controller
@RequestMapping("/car/spec")
public class CarSpecController extends BaseController
{
    private String prefix = "car/spec";

    @Autowired
    private ICarSpecService carSpecService;

    @RequiresPermissions("car:spec:view")
    @GetMapping()
    public String spec()
    {
        return prefix + "/spec";
    }

    /**
     * 查询车辆规格列表
     */
    @RequiresPermissions("car:spec:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarSpec carSpec)
    {
        startPage();
        List<CarSpec> list = carSpecService.selectCarSpecList(carSpec);
        return getDataTable(list);
    }

    /**
     * 导出车辆规格列表
     */
    @RequiresPermissions("car:spec:export")
    @Log(title = "车辆规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CarSpec carSpec)
    {
        List<CarSpec> list = carSpecService.selectCarSpecList(carSpec);
        ExcelUtil<CarSpec> util = new ExcelUtil<CarSpec>(CarSpec.class);
        return util.exportExcel(list, "spec");
    }

    /**
     * 新增车辆规格
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆规格
     */
    @RequiresPermissions("car:spec:add")
    @Log(title = "车辆规格", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CarSpec carSpec)
    {
        return toAjax(carSpecService.insertCarSpec(carSpec));
    }

    /**
     * 修改车辆规格
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CarSpec carSpec = carSpecService.selectCarSpecById(id);
        mmap.put("carSpec", carSpec);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆规格
     */
    @RequiresPermissions("car:spec:edit")
    @Log(title = "车辆规格", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CarSpec carSpec)
    {
        return toAjax(carSpecService.updateCarSpec(carSpec));
    }

    /**
     * 删除车辆规格
     */
    @RequiresPermissions("car:spec:remove")
    @Log(title = "车辆规格", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(carSpecService.deleteCarSpecByIds(ids));
    }
}
